$(function () {
    // 查询品牌
    $.ajax({
        url:"/orderManage/queryBrand",
        type:"post",
        dataType:"json",
        success:function (r) {
            let str = "<option>请选择</option>";
            if (r!=null){
                for (let i = 0; i < r.length; i++) {
                    str += "<option value='"+r[i].brandId+"'>"+r[i].brandName+"</option>"
                }
                $(".brand").html(str);
            }
            $(".brand").html(str);
        }
    })
})

function queryType(a) {
    let brandId = $(a).children("option:selected").val();
    $.ajax({
        url:"/orderManage/queryTypeByBrand",
        type: "post",
        data:{"brandId":brandId},
        dataType: "json",
        success:function (r) {
            // console.log(r)
            let str = "<option>请选择</option>";
            if (r!=null){
                for (let i = 0; i < r.length; i++) {
                    str += "<option value='"+r[i].typeId+"'>"+r[i].typeName+"</option>"
                }
                $(a).parent().next().children().html(str);
            }
            $(a).parent().next().children().html(str)
        }
    })

}

function queryModel(a) {
    let typeId = $(a).children("option:selected").val();
    // console.log(typeId)
    $.ajax({
        url:"/orderManage/queryModelByType",
        type: "post",
        data:{"typeId":typeId},
        dataType: "json",
        success:function (r) {
            console.log(r)
            let str = "<option>请选择</option>";
            if (r!=null){
                for (let i = 0; i < r.length; i++) {
                    str += "<option value='"+r[i].productId+"'>"+r[i].productModel+"</option>"
                }
                $(a).parent().next().children().html(str);
            }
            $(a).parent().next().children().html(str)
        }
    })

}

function getProductDetail(a) {
    let productId = $(a).children("option:selected").val();
    $.ajax({
        url:"/orderManage/queryProductDetail",
        ty:"post",
        data:{"productId":productId},
        dataType:"json",
        success:function (r) {
            if (r!=null){
                $(a).parent().next().next().html("<input type='text' value='"+r.productUnit+"' disabled='disabled'>");
                $(a).parent().next().next().next().html("<input type='text' value='"+r.productPrice+"' disabled='disabled'>");
            }
        }
    })
}

function saveInfo(a) {
// if (con){
//     for (var i=0;i<number;i++){
//         if ($(".tablelist>tbody>tr:eq("+i+")>td>input[name='details']").prop("checked")){
            var productId=$(".tablelist>tbody>tr>td:eq(3)>select option:selected").val();
            var type=$(".tablelist>tbody>tr>td:eq(2)>select option:selected").val();
            var brandId=$(".tablelist>tbody>tr>td:eq(1)>select option:selected").val();
            var num=$(".tablelist>tbody>tr>td:eq(4)>input").val();
            var price=$(".tablelist>tbody>tr>td:eq(6)>input").val();
            var totalprice=$(".tablelist>tbody>tr>td:eq(7)>input").val();
            var orderid=$("input[name='orderid']").val();

        // }
    let b = [];
        b.push({"brandId":brandId,"type":type,"productId":productId,"num":num,"price":price,"totalprice":totalprice,"orderid":orderid})
    // }

    $.ajax({
        url:"/orderManage/detailAdd",
        type:"POST",
        contentType: 'application/json; charset=UTF-8',
        data:JSON.stringify(b),
        dataType:"json",
        success:function (result) {
            window.location.href="/order/orderList";
        }
    })
// }else {
//     alert("完成订单详细数据后再提交！")
// }
}
